/**
 * Copyright (c) 2018-2025, NXOS Development Team
 * SPDX-License-Identifier: Apache-2.0
 * 
 * Contains: ring buffer
 * 
 * Change Logs:
 * Date           Author            Notes
 * 2025-06-10     JasonHu           Init
 */

#ifndef __UTILS_RING_BUFFER_H__
#define __UTILS_RING_BUFFER_H__

#include <nxos_mini.h>

typedef struct NX_RingBuffer
{
    NX_U8 * buffer;
    NX_Size size;
    NX_Size in;
    NX_Size out;
} NX_RingBuffer;

NX_Error NX_RingBufferInit(NX_RingBuffer * ring, NX_U8 * buffer, NX_Size size);
NX_RingBuffer * NX_RingBufferCreate(NX_Size size);
void NX_RingBufferDestroy(NX_RingBuffer * ring);

NX_Size NX_RingBufferWrite(NX_RingBuffer * ring, const NX_U8 * buffer, NX_Size len);
NX_Size NX_RingBufferRead(NX_RingBuffer * ring, const NX_U8 * buffer, NX_Size len);
NX_Size NX_RingBufferPeek(NX_RingBuffer * ring, const NX_U8 * buffer, NX_Size len);

void NX_RingBufferReset(NX_RingBuffer *ring);
NX_Size NX_RingBufferLen(NX_RingBuffer *ring);
NX_Size NX_RingBufferAvaliable(NX_RingBuffer *ring);

#endif /* __UTILS_RING_BUFFER_H__ */
